<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>Aria: moduleExample_Mod.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Aria
   &#160;<span id="projectnumber">2.9.4</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('moduleExample_Mod_8cpp-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">moduleExample_Mod.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>Example demonstrating how to implement a module with ArModuleThis is a simple example of how to define a module of code that <a class="el" href="classAria.html" title="Contains global initialization, deinitialization and other global functions. ">Aria</a>'s <a class="el" href="classArModuleLoader.html" title="Dynamic ArModule loader. ">ArModuleLoader</a> class can dynamically load at runtime. On Windows, loadable modules are DLL files. On Linux, they are shared object (.so) files (ARIA's Makefiles can compile any source file ending in "Mod.cpp" into a .so, so to build this module, run "make moduleExample_Mod.so"). <a class="el" href="classArModuleLoader.html" title="Dynamic ArModule loader. ">ArModuleLoader</a> knows about these platform conventions, so only the base name (without the .dll or .so suffix) is used to load it. To implement a loadable module, you derive a class from <a class="el" href="classArModule.html" title="Dynamicly loaded module base class, read warning in more. ">ArModule</a>, instantiate the pure virtual functions init() and exit(), and create an instance of that class. The two functions simply print out the equivalent of Hello World. An important part is the global instance of the class and the call to the macro ARDEF_MODULE(). Without that macro invocation, <a class="el" href="classAria.html" title="Contains global initialization, deinitialization and other global functions. ">Aria</a> will never be able to invoke those two functions.</p>
<p>The program moduleExample.cpp is designed to load this module and check the error return.</p>
<dl class="section see"><dt>See also</dt><dd>moduleExample.cpp. </dd>
<dd>
<a class="el" href="classArModule.html" title="Dynamicly loaded module base class, read warning in more. ">ArModule</a> in the reference manual.</dd></dl>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;Aria.h&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">class </span>SimpleMod : <span class="keyword">public</span> <a name="_a0"></a><a class="code" href="classArModule.html">ArModule</a></div><div class="line">{</div><div class="line"><span class="keyword">public</span>:</div><div class="line"></div><div class="line">  <span class="keywordtype">bool</span> <a name="a1"></a><a class="code" href="classArModule.html#a6774bb941d02907c8e4187011a9f3f8d">init</a>(<a name="_a2"></a><a class="code" href="classArRobot.html">ArRobot</a> *robot, <span class="keywordtype">void</span> *argument = NULL);</div><div class="line">  <span class="keywordtype">bool</span> <a name="a3"></a><a class="code" href="classArModule.html#a6556f5f806fbbd4f25b0c6f0c2997984">exit</a>();</div><div class="line">};</div><div class="line"></div><div class="line">SimpleMod aModule;</div><div class="line">ARDEF_MODULE(aModule);</div><div class="line"></div><div class="line"><span class="keywordtype">bool</span> SimpleMod::init(<a class="code" href="classArRobot.html">ArRobot</a> *robot, <span class="keywordtype">void</span> *argument)</div><div class="line">{</div><div class="line">  <a name="a4"></a><a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a name="a5"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;module: init(%p) called in the loaded module!&quot;</span>, robot);</div><div class="line">  <span class="keywordflow">if</span> (argument != NULL)</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;module: Argument given to ArModuleLoader::load was the string &#39;%s&#39;.&quot;</span>, </div><div class="line">       (<span class="keywordtype">char</span> *)argument);</div><div class="line">  <span class="keywordflow">else</span></div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;module: No argument was given to ArModuleLoader (this is OK).&quot;</span>);</div><div class="line">    </div><div class="line">  <span class="comment">// Do stuff here...</span></div><div class="line">    </div><div class="line">  <span class="keywordflow">return</span>(<span class="keyword">true</span>);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">bool</span> SimpleMod::exit()</div><div class="line">{</div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;module: exit() called.&quot;</span>);</div><div class="line"></div><div class="line">  <span class="comment">// Do stuff here...</span></div><div class="line"></div><div class="line">  <span class="keywordflow">return</span>(<span class="keyword">true</span>);</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
